﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using Hardanger.Model;
using System.ComponentModel;
using Hardanger.Features.ServerFuzzer;

namespace Hardanger.ViewModel
{
	public class HardangerViewModel : INotifyPropertyChanged
	{
        static private HardangerViewModel _current = null;
        static public HardangerViewModel Current
        {
            get
            {
                return _current;
            }
        }

        public HardangerViewModel()
        {
            _current = this;
        }

        private int _fuzzingSessionId = 0;
        public int FuzzingSessionId { 
            get 
            {
                return _fuzzingSessionId;
            } 
            set 
            {
                _fuzzingSessionId = value;
                onPropertyChanged(this, "FuzzingSessionId");
            } 
        }

        
		public ObservableCollection<FeatureResult> Results
		{
			get 
			{
				return ResultsManager.FeatureResults;				
			}
		}


        public ServerFuzzerMasterEngine ServerFuzzerMaster
        {
            get
            {
                return ServerFuzzerMasterEngine.Current;
            }
        }

		private ServerFuzzerViewModel _serverFuzzer = new ServerFuzzerViewModel();
		public ServerFuzzerViewModel ServerFuzzer
		{
			get
			{
				return _serverFuzzer;
			}
			set
			{
				_serverFuzzer = value;
                onPropertyChanged(this, "ServerFuzzer");

			}
		}

        private ResultsViewViewModel _resultsVm = new ResultsViewViewModel();
        public ResultsViewViewModel ResultsVm
        {
            get { return _resultsVm; }
            set
            {
                _resultsVm = value;
                onPropertyChanged(this, "ResultsVm");
            }
        }

		public ObservableCollection<HardangerSession> AllSessions
		{
			get
			{
				return SessionManager.Current.AllSessions;
			}
		}

		private HardangerSession _selectedSession;
		public HardangerSession SelectedSession
		{
			get
			{
				return _selectedSession;
			}
			set
			{
				_selectedSession = value;
				ServerFuzzerViewModel.SetCurrent(_selectedSession);
				if (_selectedSession != null)
				{
					ServerFuzzer = ServerFuzzerViewModel.ServerFuzzerViewModelList[_selectedSession.FiddlerId];
				}
				else
				{
					ServerFuzzer = null;
				}
				onPropertyChanged(this, "SelectedSession");
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;
		public void onPropertyChanged(object sender, string e)
		{
			PropertyChanged(sender, new PropertyChangedEventArgs(e));
		}
	}
}
